<html><head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"><title>CocoaMessage</title></head>
<body bgcolor="#EFF1F0" link="#3A3966" vlink="#000000" alink="#000000">
<font face="Verdana, sans-serif" size="2"><p align="center"><b><font size="4">CocoaMessage()</font></b></p>
<p><b>语法</b></p><blockquote>

Result = <font color="#3A3966"><b>CocoaMessage</b></font>(ReturnValueAddress, Object, Method$ [, ParameterValue [, Parameter$, [, ParamaterValue, ...]]])</blockquote>

<b>概要</b><br><blockquote>



For advanced users. Available on OS X only, it allows to easily send an Objective-C message to the OS X framework and access 
any API. Usually Objective-C use brackets to have a clear syntax for messages. As PureBasic doesn't have built-in Objective-C 
support, it needs to emulate it, so the syntax is a bit different. Once learnt, it's easy to call the required API. 
To get more examples, please read the following thread on the <a href="http://www.purebasic.fr/english/viewtopic.php?f=19&amp;t=50795">forums</a>. 

 

</blockquote><p><b>参数</b></p><blockquote>
<style type="text/css">
table.parameters { border-spacing: 0px; border-style: none; border-collapse: collapse; }
table.parameters td { border-width: 1px; padding: 6px; border-style: solid; border-color: gray; vertical-align: top; font-family:Arial; font-size:10pt; }
</style>
<table width="90%" class="parameters">
<tr><td width="10%"><i>ReturnValueAddress</i></td>
<td width="90%"> 
 
If the API call return a structure or a type different than 'integer', this field is used to set the returning result. 
An address to the structure or variable needs to be specified. If zero is specified, the result will be ignored. 

 

</td></tr>
<tr><td><i>Object</i></td>
<td> 
 
The object on which the Objective-C methods will be called. It can be zero if the method is a static method 
(mostly when creating an object). 

 

</td></tr>
<tr><td><i>Method$</i></td>
<td> 
 
The method to call on the object, usually followed by a semicolon (':'). If the method needs a structure as parameter, '@' 
needs to be appended after the semicolon. If the method expect a string as parameter, '$' can be appended after the 
semicolon, so the string will be automatically converted in a temporary NSString. This is not required, but it can be useful 
and ease the coding. If the method isn't supported by the object, a debugger message will be raised at runtime. 

 

</td></tr>
<tr><td><i>ParameterValue (optional)</i></td>
<td> 
 
The parameter value associated to the previous method. 

 

</td></tr>
<tr><td><i>Parameter$ (optional)</i></td>
<td> 
 
The next method parameter. PureBasic support up to 7 method parameters. 

 

</td></tr>
</table>
</blockquote><p><b>返回值</b></p><blockquote>



Integer return value. Useful for object creation id. 

 

</blockquote><p><b>备注</b></p><blockquote>



PureBasic has already setup a temporary memory pool which is flushed every time <a href="../window/windowevent.html">WindowEvent()</a> or <a href="../window/waitwindowevent.html">WaitWindowEvent()</a> is called. If you need 
to release big objects immediately, you will have to create a local memory pool around your calls. 

 

</blockquote><p><b>Example:</b> with string</p><blockquote>

<pre><font face="Courier New, Courier, mono"size="2">  <font color="#3A3966">; Objective-C: </font>
  <font color="#3A3966">;   ColorList = [NSColorList colorListNamed:@"Crayons"];</font>
  <font color="#3A3966">;</font>
  ColorList =<font color="#3A3966"> CocoaMessage</font>(0, 0, "NSColorList colorListNamed:$", @"Crayons") <font color="#3A3966">; Will create an NSString for "Crayons" under the hood (respecting ascii/unicode mode of the program)</font>
</font></pre>

</blockquote><p><b>Example:</b> with complex type</p><blockquote>

<pre><font face="Courier New, Courier, mono"size="2">  <font color="#3A3966">; Objective-C: </font>
  <font color="#3A3966">;   Transform = [NSAffineTransform transform];</font>
  <font color="#3A3966">;</font>
  Transform =<font color="#3A3966"> CocoaMessage</font>(0, 0, "NSAffineTransform transform") <font color="#3A3966">; Get an identity transform</font>

  <font color="#3A3966">; Objective-C: </font>
  <font color="#3A3966">;   [TransForm scaleXBy:sx yBy:sy];</font>
  <font color="#3A3966">;</font>
  sx.CGFloat = 5.5
  sy.CGFloat = 20
<font color="#3A3966">  CocoaMessage</font>(0, TransForm, "scaleXBy:@", @sx, "yBy:@", @sy) <font color="#3A3966">; Scale x by 5.5, y by 20. As sx is not an integer, '@' needs to be specified</font>
  
  <font color="#3A3966">; Objective-C: </font>
  <font color="#3A3966">;   NSAffineTransform TransformStruct = [TransForm transformStruct];</font>
  <font color="#3A3966">;</font>
<font color="#3A3966">  CocoaMessage</font>(@TransformStruct.NSAffineTransform, TransForm, "transformStruct") <font color="#3A3966">; Get the transform structure</font>
  
  <b><font color="#3A3966">Debug</font></b> TransformStruct\m11 <font color="#3A3966">; debug outputs 5.5</font>
</font></pre>

</Blockquote><p><b>已支持操作系统 </b><Blockquote>MacOS X</Blockquote></p><center>&lt;- <a href=cpuname.html>CPUName()</a> - <a href="index.html">System Index</a> - <a href="computername.html">ComputerName()</a> -&gt;<br><br>

</body></html>